//
//  RCBaseViewController.m
//  RCSideMenu
//
//  Created by razeen on 1/18/16.
//  Copyright © 2016 Razeen. All rights reserved.
//
#import "AppDelegate.h"
#import "RCBaseViewController.h"

@interface RCBaseViewController ()

@end

@implementation RCBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self UIGlobal];
    [self addObserverGlobal];
    // Do any additional setup after loading the view.
}

- (void)dealloc
{
    [self removeObserverGlobal];
}

- (void)UIGlobal
{}

#pragma mark  - 全局通知
- (void)addObserverGlobal{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getNotif:) name:kTDGlobalNotification object:nil];
}

- (void)removeObserverGlobal{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kTDGlobalNotification object:nil];
}

- (void)getNotif:(NSNotification *)noti{
    
    NSDictionary *dd=noti.userInfo;
    NSInteger ty=-1;
    id data;
    id obj;
    
    if ([dd objectForKey:@"type"] && [[dd objectForKey:@"type"] isKindOfClass:[NSNumber class]]) {
        ty=[[dd objectForKey:@"type"]integerValue];
    }
    data=[dd objectForKey:@"data"];
    obj=[dd objectForKey:@"object"];
    [self getNotifType:ty data:data target:obj];
}

- (void)getNotifType:(TDNotificationType)type data:(id)data target:(id)obj
{}



- (UIButton *)leftMenuBtn
{
    if (!_leftMenuBtn) {
        _leftMenuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_leftMenuBtn setImage:[UIImage imageNamed:@"menu_icon"] forState:UIControlStateNormal];
        [_leftMenuBtn sizeToFit];
        [_leftMenuBtn addTarget:self action:@selector(clickLeftMenuBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftMenuBtn;
}

- (void)setHasLeftMenuBtn:(BOOL)hasLeftMenuBtn
{
    _hasLeftMenuBtn = hasLeftMenuBtn;
    if (_hasLeftMenuBtn) {
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.leftMenuBtn];
    }
    else
    {
        
    }
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    
        if (APPDELEGATE.mainVC.menuState == kMainVCMenuStateMenu) {

            [APPDELEGATE.mainVC showHomeWhatever];
        }
}


- (void)clickLeftMenuBtnAction:(id)sender
{
    
    if (APPDELEGATE.mainVC.menuState == kMainVCMenuStateHome) {
        [APPDELEGATE.mainVC showMenu];
    }
    else
    {
        [APPDELEGATE.mainVC showHome];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
